package com.coupon.dal.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "customer")
@Cache(region = "couponRegion", usage = CacheConcurrencyStrategy.READ_WRITE)
public class Customer {

	private Long id;
	private User contactPerson;
	private Integer categoryId; // todo enum [Food,Electric]

	@OneToOne
	@JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID", nullable = false)
	public User getContactPerson() {
		return contactPerson;
	}

	public void setContactPerson(User contactPerson) {
		this.contactPerson = contactPerson;
	}

	@Id
	@GeneratedValue(generator = "hibernateSequence")
	@SequenceGenerator(name = "hibernateSequence", sequenceName = "HIBERNATE_SEQUENCE")
	@Column(name = "CUSTOMER_ID", nullable = false, length = 12)
	public Long getId() {
		return id;
	}
	
	

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Integer categoryId) {
		this.categoryId = categoryId;
	}

	@Override
	public int hashCode() {
		return (id != null ? id.hashCode() : 0);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Customer that = (Customer) o;

		if (id != null ? !id.equals(that.id) : that.id != null)
			return false;

		return true;
	}

}
